<?php
class SoctestsController extends AppController {

	var $name = 'Soctests';

	function index() {
		$data = false;
#pr ($this->data);
		$this->loadModel('Socdesc');
		$data['socDesc'] = $this->Socdesc->getDesc();

		if ($uid = $this->Auth->user('id')) {
			$this->loadModel('UsersSoctype');
			$uType = $this->UsersSoctype->get($uid);
			$typeid = $uType['Soctype']['id'];
		}

		$soctypeC = array();
		if (isset($this->data)) {

			if (isset($this->data['testdata'])) {
				$tData = $this->data['testdata'];
				$findType = true;
				foreach ($tData as $k => $v) {
					if (empty($v)) {
						$findType = false;
					}	
				}
			}

			if (isset($this->data['testresult'])) {
				$typeid = $this->data['testresult']['type'];
				if (isset($uid)) {
					$this->UsersSoctype->saveType($uid, $typeid);
				} else {
					$this->Session->setFlash('login needle');
					$data['loginregister'] = 1;
				}
			}


		}

		if (!empty($findType)) {
			$this->loadModel('Soctype');
			$data['typedesc'] = $this->Soctype->getType($tData);
		} elseif (isset($typeid)) {
			$this->loadModel('Soctype');
			$data['typedesc'] = $this->Soctype->getType(array('id'=>$typeid));
		}


/**
		if (isset($typeid)) {
			$testdata['ei'] = $data['typeslist'][0]['Soctype']['ei'];	
			$testdata['sn'] = $data['typeslist'][0]['Soctype']['sn'];	
			$testdata['ft'] = $data['typeslist'][0]['Soctype']['ft'];	
			$testdata['pj'] = $data['typeslist'][0]['Soctype']['pj'];

	//		$this->data['testdata'] = $testdata;
		}
*/


		if ($data) {
			$this->set($data);
		}
	}

}
?>
